package com.hdax.dmw.scheduler.mapstruct;

import com.hdax.dmw.entity.scheduler.SchedulerSeatPrice;
import com.hdax.dmw.scheduler.dtos.PriceDto;
import com.hdax.dmw.scheduler.service.SchedulerSeatService;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Mapper(componentModel = "spring")
public abstract class PriceDtoMapper {

    @Autowired
    private SchedulerSeatService seatService;

    public Short isHaveSeat(Integer seatNum, Long scheduleId,Integer areaLevel){
        int saleCount = seatService.getSaleCount(scheduleId,areaLevel);
        if(seatNum == saleCount){
            return 0;
        }
        return 1;
    }

    @Mappings({
            @Mapping(target = "isHaveSeat",expression = "java(isHaveSeat(source.getSeatNum(),source.getScheduleId(),source.getAreaLevel()))")
    })
    public abstract PriceDto toTarget(SchedulerSeatPrice source);
    public abstract List<PriceDto> toTargetList(List<SchedulerSeatPrice> sources);
}
